//
//  CZProfileViewController.swift
//  GZWeibo007
//
//  Created by Apple on 15/12/15.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
import SVProgressHUD
import SDWebImage




class CZProfileViewController: CZBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        prepareUI()
        
        readCacheSize()
    }
    
    //读取缓存大小
    func readCacheSize() {
    
        SDWebImageManager.sharedManager().imageCache.calculateSizeWithCompletionBlock { (a, b) -> Void in
            print(NSHomeDirectory())
            self.label.text = "缓存大小:\(CGFloat(b) / 1000 / 1000.0) M"
        }
    }
    //准备UI
   func prepareUI() {
    
       view.addSubview(label)
        view .addSubview(cleaButton)
    
    label.frame = CGRect(x: 30, y: 90, width: 260, height: 40)
    cleaButton.frame = CGRect(x: 30, y: 180, width: 100, height: 30)
    }
    
    //清理
    func clear() {
    
        SDWebImageManager.sharedManager().imageCache.clearDiskOnCompletion { () -> Void in
            SVProgressHUD.showSuccessWithStatus("清除缓存成功")
            self.readCacheSize()
        }
    
    }
    
    
    
    //MARK: - 懒加载
    //显示有多少缓存
    private lazy var label = UILabel()
    
    //清除按钮
    private lazy var cleaButton: UIButton = {
    
        let button = UIButton()
        button.setTitle("清除缓存", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        button.addTarget(self, action: "clear", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
}
